/**
 * Copyright &copy; 2013-2019 山东易科德软件有限公司
 * All rights reserved.
 */
package com.uniedp.modules.mdm.controller;
import com.uniedp.core.annotation.LogOperation;
import com.uniedp.core.constant.Constant;
import com.uniedp.core.page.PageData;
import com.uniedp.core.utils.ExcelUtils;
import com.uniedp.core.utils.Result;
import com.uniedp.core.validator.AssertUtils;
import com.uniedp.core.validator.ValidatorUtils;
import com.uniedp.core.validator.group.AddGroup;
import com.uniedp.core.validator.group.DefaultGroup;
import com.uniedp.core.validator.group.UpdateGroup;
import com.uniedp.modules.mdm.dto.MdmInventoryZp1DTO;
import com.uniedp.modules.mdm.excel.MdmInventoryZp1Excel;
import com.uniedp.modules.mdm.service.MdmInventoryZp1Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
 * mdm_inventory_zp1
 * zhouController
 * @author zhou
 * @since  2021-09-09
 */
@RestController
@RequestMapping("mdm/mdmInventoryZp1")
@Api(tags="")
public class MdmInventoryZp1Controller {
    @Autowired
    private MdmInventoryZp1Service mdmInventoryZp1Service;
    @GetMapping("page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
        @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
        @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
    @RequiresPermissions("mdm:mdmInventoryZp1:page")
    public Result<PageData<MdmInventoryZp1DTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<MdmInventoryZp1DTO> page = mdmInventoryZp1Service.page(params);
        return new Result<PageData<MdmInventoryZp1DTO>>().ok(page);
    }
    @GetMapping("{id}")
    @ApiOperation("信息")
    @RequiresPermissions("mdm:mdmInventoryZp1:info")
    public Result<MdmInventoryZp1DTO> get(@PathVariable("id") Long id){
        MdmInventoryZp1DTO data = mdmInventoryZp1Service.get(id);
        return new Result<MdmInventoryZp1DTO>().ok(data);
    }
    @GetMapping("list")
    @ApiOperation("列表")
    @RequiresPermissions("mdm:mdmInventoryZp1:info")
    public Result<List<MdmInventoryZp1DTO>> list(@ApiIgnore @RequestParam Map<String, Object> params) {
        List<MdmInventoryZp1DTO> list = mdmInventoryZp1Service.list(params);
        return new Result<List<MdmInventoryZp1DTO>>().ok(list);
    }

    @PostMapping
    @ApiOperation("保存")
    @LogOperation("保存")
    @RequiresPermissions("mdm:mdmInventoryZp1:save")
    public Result save(@RequestBody MdmInventoryZp1DTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
        mdmInventoryZp1Service.save(dto);
        return new Result().ok(dto);
    }
    @PutMapping
    @ApiOperation("修改")
    @LogOperation("修改")
    @RequiresPermissions("mdm:mdmInventoryZp1:update")
    public Result update(@RequestBody MdmInventoryZp1DTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
        mdmInventoryZp1Service.update(dto);
        return new Result().ok(dto);
    }


    @DeleteMapping
    @ApiOperation("删除")
    @LogOperation("删除")
    @RequiresPermissions("mdm:mdmInventoryZp1:delete")
    public Result delete(@RequestBody Long[] ids){
        //效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        mdmInventoryZp1Service.delete(ids);
        return new Result();
    }

    @PostMapping("action")
    @ApiOperation("启用")
    @LogOperation("启用")
    @RequiresPermissions("mdm:mdmInventoryZp1:action")
    public Result action(@RequestBody Long[] ids){
        //效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        mdmInventoryZp1Service.action(ids);
        return new Result();
    }

    @PostMapping("stop")
    @ApiOperation("停用")
    @LogOperation("停用")
    @RequiresPermissions("mdm:mdmInventoryZp1:stop")
    public Result stop(@RequestBody Long[] ids){
        //效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        mdmInventoryZp1Service.stop(ids);
        return new Result();
    }

    @GetMapping("export")
    @ApiOperation("导出")
    @LogOperation("导出")
    @RequiresPermissions("mdm:mdmInventoryZp1:export")
    public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
        List<MdmInventoryZp1DTO> list = mdmInventoryZp1Service.list(params);
        ExcelUtils.exportExcelToTarget(response, null, list, MdmInventoryZp1Excel.class);
    }
}